//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_base.h"
#include "h_xml.h"
#include "h_global.h"
using namespace h_base;
using namespace h_xml;

#include "h_g.h"
#include "h_portal.h"
#include "h_server.h"

#include "t_conditionform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TConditionForm *ConditionForm;
//---------------------------------------------------------------------------
__fastcall TConditionForm::TConditionForm(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
bool __fastcall TConditionForm::ChangeCondition(HBatchIcon *Batch, const UTF8String &JobName, bool &CondNot,
   UTF8String &ConditionFile, UTF8String &SpecialDate,
   UTF8String &LoopStartTime, UTF8String &LoopEndTime, const UTF8String &Auth)
{
   CreateSpecialDateList(ComboBoxSpecialDate, h_g::SpecialDateList);
   EditJobName->Text = JobName;
   CheckBoxCondNot->Checked = CondNot;
   EditConditionFile->Text = ConditionFile;

   if( ComboBoxSpecialDate->Items->IndexOf(SpecialDate) == -1 )
      ComboBoxSpecialDate->ItemIndex = 0;
   else
      ComboBoxSpecialDate->ItemIndex =
         ComboBoxSpecialDate->Items->IndexOf(SpecialDate);

   EditLoopStartTime->Text = LoopStartTime;
   EditLoopEndTime->Text = LoopEndTime;

   if ( !h_g::RememberPasswordFlag )
   {
      EditPassword->Text = "";
   }

   OkFlag = false;
   ShowModal();

   if ( !OkFlag )
   {
      return false;
   }

   UTF8String Id = EditId->Text.TrimRight();
   UTF8String Password = EditPassword->Text.TrimRight();
   UTF8String ErrStr;

   if ( !HServer::FuncLogin(Batch, Id, Password, Auth, ErrStr) )
   {
      return false;
   }

   Batch->Lock();
   Batch->LastLoginId = Id;
   Batch->Unlock();
   SpecialDate = ComboBoxSpecialDate->Text.TrimRight();
   CondNot = CheckBoxCondNot->Checked;
   ConditionFile = EditConditionFile->Text.TrimRight();
   LoopStartTime = EditLoopStartTime->Text.TrimRight();
   LoopEndTime = EditLoopEndTime->Text.TrimRight();
   return true;
}

void __fastcall TConditionForm::ButtonOkClick(TObject *Sender)
{
   OkFlag = true;
   Close();
}
//---------------------------------------------------------------------------
void __fastcall TConditionForm::ButtonCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------
void __fastcall TConditionForm::FormShow(TObject *Sender)
{
   if ( EditId->Text == "" )
   {
      EditId->SetFocus();
   }
   else
   {
      EditPassword->SetFocus();
   }
}
//---------------------------------------------------------------------------


